<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>考试页面 - 音乐考试系统</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 15px 35px rgba(0,0,0,0.1);
        }
        .exam-header {
            text-align: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 2px solid #f0f0f0;
        }
        .exam-title {
            color: #333;
            font-size: 28px;
            margin-bottom: 10px;
        }
        .timer {
            position: fixed;
            top: 20px;
            right: 20px;
            background: #667eea;
            color: white;
            padding: 15px 20px;
            border-radius: 10px;
            font-size: 18px;
            font-weight: bold;
            box-shadow: 0 5px 15px rgba(102,126,234,0.3);
        }
        .question {
            margin-bottom: 30px;
            padding: 25px;
            background: #f8f9fa;
            border-radius: 12px;
            border-left: 5px solid #667eea;
            transition: all 0.3s ease;
        }
        .question:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }
        .question-title {
            font-size: 18px;
            color: #333;
            margin-bottom: 20px;
            font-weight: bold;
            line-height: 1.5;
        }
        .options {
            display: grid;
            gap: 12px;
        }
        .option-label {
            display: flex;
            align-items: center;
            padding: 15px;
            background: white;
            border: 2px solid #e1e1e1;
            border-radius: 10px;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        .option-label:hover {
            border-color: #667eea;
            background: #f0f4ff;
            transform: translateX(5px);
        }
        .option-label.selected {
            border-color: #28a745;
            background: #e8f5e8;
        }
        .option-label input {
            margin-right: 15px;
            transform: scale(1.2);
        }
        .option-text {
            display: flex;
            align-items: center;
            font-size: 16px;
        }
        .option-letter {
            display: inline-block;
            width: 28px;
            height: 28px;
            background: #667eea;
            color: white;
            border-radius: 50%;
            text-align: center;
            line-height: 28px;
            margin-right: 15px;
            font-weight: bold;
        }
        .submit-btn {
            display: block;
            width: 200px;
            margin: 40px auto 0;
            padding: 15px;
            background: #28a745;
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 18px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        .submit-btn:hover {
            background: #218838;
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(40,167,69,0.3);
        }
        .progress-bar {
            background: #e9ecef;
            border-radius: 10px;
            height: 8px;
            margin: 20px 0;
            overflow: hidden;
        }
        .progress {
            background: #28a745;
            height: 100%;
            transition: width 0.3s ease;
        }
        .progress-text {
            text-align: center;
            color: #666;
            margin-bottom: 10px;
            font-size: 14px;
        }
        .question-counter {
            text-align: center;
            color: #667eea;
            font-weight: bold;
            margin-bottom: 20px;
            font-size: 16px;
        }
        .nav-btn {
            padding: 12px 25px;
            background: #667eea;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            margin: 0 10px;
        }
        .nav-btn:hover {
            background: #5a6fd8;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102,126,234,0.3);
        }
        .nav-btn:disabled {
            background: #6c757d;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }
        .nav-btn.prev {
            background: #6c757d;
        }
        .nav-btn.prev:hover:not(:disabled) {
            background: #5a6268;
        }
        .navigation {
            display: flex;
            justify-content: space-between;
            margin-top: 25px;
            align-items: center;
        }
    </style>
</head>
<body>
    <div class="timer" id="timer">剩余时间: 60:00</div>
    
    <div class="container">
        <div class="exam-header">
            <h1 class="exam-title">{{ exam.title }}</h1>
            <p style="color: #666;">请认真作答，祝您考试顺利！</p>
        </div>
        
        <div class="question-counter" id="questionCounter">题目 1 / {{ questions|length }}</div>
        <div class="progress-bar">
            <div class="progress" id="progressBar" style="width: 0%"></div>
        </div>
        <div class="progress-text" id="progressText">已完成 0%</div>
        
        <form method="POST" id="examForm">
            {% for question in questions %}
            <div class="question" id="question-{{ loop.index0 }}" style="display: {% if loop.index0 == 0 %}block{% else %}none{% endif %};">
                <div class="question-title">
                    {{ loop.index }}. {{ question.content }}
                </div>
                <div class="options">
                    {% for option in question.options %}
<label class="option-label" data-question="{{ loop.index0 }}" data-option="{{ loop.index0 }}">
    <input type="radio" 
           name="q{{ loop.index0 }}" 
           value="{{ option }}"
           onchange="selectOption(this)">
    <div class="option-text">
        <span class="option-letter">{{ ['A','B','C','D'][loop.index0] }}</span>
        {{ option }}
    </div>
</label>
{% endfor %}
                </div>
                
                <div class="navigation">
                    <button type="button" class="nav-btn prev" onclick="showQuestion({{ loop.index0 - 1 }})" {% if loop.index0 == 0 %}disabled{% endif %}>
                        ← 上一题
                    </button>
                    
                    {% if loop.index < questions|length %}
                    <button type="button" class="nav-btn next" onclick="showQuestion({{ loop.index0 + 1 }})">
                        下一题 →
                    </button>
                    {% else %}
                    <button type="submit" class="submit-btn">提交试卷</button>
                    {% endif %}
                </div>
            </div>
            {% endfor %}
        </form>
    </div>

    <script>
        let currentQuestion = 0;
        const totalQuestions = {{ questions|length }};
        const answeredQuestions = new Set();
        
        // 更新进度
        function updateProgress() {
            const progress = (answeredQuestions.size / totalQuestions) * 100;
            document.getElementById('progressBar').style.width = progress + '%';
            document.getElementById('progressText').textContent = `已完成 ${Math.round(progress)}%`;
        }
        
        // 显示指定题目
        function showQuestion(index) {
            if (index >= 0 && index < totalQuestions) {
                document.getElementById('question-' + currentQuestion).style.display = 'none';
                document.getElementById('question-' + index).style.display = 'block';
                currentQuestion = index;
                
                document.getElementById('questionCounter').textContent = `题目 ${index + 1} / ${totalQuestions}`;
                updateProgress();
                
                // 更新导航按钮状态
                updateNavigationButtons();
            }
        }
        
        // 更新导航按钮状态
        function updateNavigationButtons() {
            const prevButtons = document.querySelectorAll('.nav-btn.prev');
            prevButtons.forEach(btn => {
                btn.disabled = currentQuestion === 0;
            });
        }
        
        // 选择选项
        function selectOption(radio) {
            const label = radio.parentElement;
            const questionIndex = parseInt(label.getAttribute('data-question'));
            
            // 移除同题目其他选项的选中状态
            const options = document.querySelectorAll(`[data-question="${questionIndex}"]`);
            options.forEach(opt => opt.classList.remove('selected'));
            
            // 添加选中状态
            label.classList.add('selected');
            
            // 记录已回答的题目
            answeredQuestions.add(questionIndex);
            updateProgress();
        }
        
        // 倒计时功能
        let timeLeft = {{ exam_time * 60 }};
        const timer = document.getElementById('timer');
        
        function updateTimer() {
            const minutes = Math.floor(timeLeft / 60);
            const seconds = timeLeft % 60;
            timer.textContent = `剩余时间: ${minutes}:${seconds.toString().padStart(2, '0')}`;
            
            if (timeLeft <= 0) {
                alert('考试时间到！将自动提交答案。');
                document.getElementById('examForm').submit();
            } else {
                timeLeft--;
                setTimeout(updateTimer, 1000);
            }
        }
        
        // 初始化
        updateTimer();
        updateProgress();
        updateNavigationButtons();
        
        // 键盘导航
        document.addEventListener('keydown', function(e) {
            if (e.key === 'ArrowLeft' && currentQuestion > 0) {
                showQuestion(currentQuestion - 1);
            } else if (e.key === 'ArrowRight' && currentQuestion < totalQuestions - 1) {
                showQuestion(currentQuestion + 1);
            }
        });
    </script>
</body>
</html>